<template>
  <div class="floor">
    <div class="floor-header">
      <h5 class="floor-header-title">
        精品推荐
      </h5>
      <div class="more">
        更多
        <van-icon class-prefix="icon" class="iconfont" name="gengduo"/>
      </div>
    </div>
    <div class="floor-main">
      <div class="item" v-for="(item,index) in floors" :key="item.id" @click="clickItem(index,item.id)">
        <img v-lazy="item.pic" alt="">
        <h5 class="item-title">
          {{item.name}}
        </h5>
        <div class="price">
          <span class="discount-price">{{item.minPrice | currency}}</span>
          <span class="original-price">{{item.originalPrice | currency}}</span>
          <van-icon @click.stop = "add_cart(item)" class-prefix="icon" color="#f66" size="18" class="iconfont" name="wuuiconxiangjifangda"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { currency } from '@/utils/filters'
export default {
  props: {
    floors: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickItem (index, id) {
      this.$emit('clickItem', { index, id })
    },
    add_cart (item) {
      // 点击加入购物车
      this.$emit('add_cart', item)
    }
  },
  filters: {
    currency
  }
}
</script>

<style lang="scss" scoped>
.floor{
  &-header{
    height: 50px;
    line-height:50px;
    font-size:14px;
    display: flex;
    padding: 0 10px;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    border-bottom:1px solid #ccc;
  }
  &-main{
    display:flex;
    flex-wrap:wrap;
    .item{
      width:50%;
      padding:0 10px;
      box-sizing: border-box;
      img{
        width:100%;
      }
      &-title{
        font-size:14px;
        color:#333;
        line-height:20px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .price{
        height:30px;
        display: flex;
        align-items: center;
        .discount-price{
          font-size:24px;
          color:#f66;
        }
        .original-price{
          font-size:16px;
          margin: 0 10px;
          color:#999;
          text-decoration: line-through;
        }
      }
    }
  }
}
</style>
